package com.start.admin.mappers;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.start.admin.entity.StartSysUser;
import com.start.common.constant.StartConstant;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SysUserMapper extends BaseMapper<StartSysUser> {

    @Select(StartConstant.MBP_SCRIPT.START + "" +
            "SELECT  " +
            "  ssu.*   " +
            "FROM  " +
            "  start_sys_user ssu  " +
            "  INNER JOIN start_sys_user_role ssur ON ssur.user_id = ssu.id   " +
            " AND ssur.role_id IN " +
            "<foreach item=\"item\" index=\"index\" collection=\"roleIds\"" +
            "  open=\"(\" separator=\",\" close=\")\"> " +
            "    #{item} " +
            "</foreach> " +
            "GROUP BY  ssu.id" +
            StartConstant.MBP_SCRIPT.END)
    List<StartSysUser> listByRoleIds(@Param("roleIds") List<String> roleIds);

    @Select(StartConstant.MBP_SCRIPT.START +
            "SELECT  " +
            "  ssu.*   " +
            "FROM  " +
            "  start_sys_user ssu  " +
            "  INNER JOIN start_sys_user_manage_dept ssumd ON ssu.dept_id = ssumd.dept_id   " +
            "  AND ssu.is_enabled = 1   " +
            "  AND ssu.id=ssumd.user_id   " +
            "  AND ssumd.dept_id = #{deptId}   " +
            "  AND ssumd.manage_level IN  " +
            "<foreach item=\"item\" index=\"index\" collection=\"manageLevelCodes\"" +
            "  open=\"(\" separator=\",\" close=\")\"> " +
            "    #{item} " +
            "</foreach> " +
            " GROUP BY ssu.id" +
            StartConstant.MBP_SCRIPT.END)
    List<StartSysUser> listByDeptManage(@Param("deptId") String deptId, @Param("manageLevelCodes") List<String> manageLevelCodes);
}
